﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using ClientLib.Common;
using ClientLib.MonitorState2;
using Bus = WpfDataBingding.TaskServiceReference;

namespace ClientLib.Logic
{
    class DynamicDeviceState
    {
        public static ChangeStateBackInfo ChangeDeviceDynamicState(DynamicState dyState, string strValue)
        {

            ChangeStateBackInfo backinfo;
            #region////暂用版本
            try
            {
            double val = Double.Parse(strValue);
            Bus.AttributeValue staval = new Bus.AttributeValue();

            staval.Type = "double";
            staval.Value = val;

            
           
            Bus.DeviceState deviceState = new Bus.DeviceState();

            deviceState.AgentID = dyState.AgentName;
            deviceState.DevID = dyState.DevID;
            deviceState.DevType = "XBPQ";
            deviceState.Name = dyState.StateName;
            deviceState.Value = staval;
          
           
           
                using (Bus.DataBusServiceClient client = new WpfDataBingding.TaskServiceReference.DataBusServiceClient())
                {
                    bool issucess = client.SetStates(new Bus.DeviceState[] { deviceState });
                    if (issucess == true)
                    {
                        backinfo = new ChangeStateBackInfo { isSucess=true, info=string.Empty};
                    }
                    else
                    {
                        backinfo = new ChangeStateBackInfo {  isSucess=false, info = string.Empty };
                    }
                    client.Close();
                }
            }
            catch(Exception e)
            {
                backinfo = new ChangeStateBackInfo { isSucess=false, info=e.Message.ToString() };
                return backinfo;
            }

            return backinfo;
            #endregion
        }

        public static IEnumerable<DeviceDynamic> GetAllMonitorDevice()
        {
         Collection monitorCollection=  Application.Current.Properties["MonitorCollection"] as Collection;
         return monitorCollection.GetDeviceList();
        }

       
    }
}
